package day01.base

object demo1_Variable {
  def main(args: Array[String]): Unit = {

    println("hello world")

    //var/val 变量名：类型=值,声明的同时必须初始化
    var name: String = "hangman"

    //强类型语言，类型可以推断出来
    name = "hangman"

    //val=final
    val age = 18
    //age=2

    println("-------------------------Type-----------------------")

    //AnyVal
    val a: Byte = 10
    val b: Short = a //隐式转换
    val c: Int = 10
    val d: Long = 10
    val e: Float = 10
    val f: Double = 10
    val g: Unit = () //void  唯一实例()
    var ss: Short = c.toShort //强转
    ss.toString  //所有的类型都提供了toString
    var s = "hello" + c  //任意类型都提供了和字符串进行拼接的方法
    //Anyref
    val arr: Array[String] = new Array[String](5)


    println("-----------------------string-----------------------")

    //所有运算符都是方法,数字其实也是对象
    //== 和 equals比较的是内容  eq比较的是地址
    val str = new String("abc")
    val str1 = new String("abc")
    println(str == str1) //true
    println(str equals str1) //true
    println(str eq str1) //false
    println(str.eq(str1)) //false

    //substring
    println(str.slice(0, 2))


    //用的是java中的字符串
    val newName: String = name.substring(0, 1)
    println(newName)
    println("hello" + newName) //拼接
    printf("hello %s,%d", newName, age) //传值
    print(s"name=$newName,age=$age")
    print(s"$newName,$age")
    print(s"${newName}字符串")

    //多行字符串   | 默认顶格符

    println(
      s"""
         |{"name":"$newName","age":"$age"}
         |""".stripMargin
    )

    println(
      s"""
         |select
         |*
         |from table
         |where name="$newName"
         |""".stripMargin
    )
  }
}



